<template>
  <div class="contioner">
    <div ref="myChart" :style="{ width: '100%', height: '100%' }"></div>
  </div>
</template>
      
  <script lang="ts" setup>
import * as echarts from 'echarts'
import { Message } from '@arco-design/web-vue'
import { ref, reactive, onMounted, watch } from 'vue'
//引入封装post
import { post } from '@/api/http'
import dayjs from 'dayjs'
//getlist初始化接口参数
let query: any = reactive({
  beginDate: dayjs().format('YYYY'), //当天日期
  planOrderCode: 32,
})
let state: any = null
window.addEventListener('resize', updateChartSize)
function updateChartSize() {
  state.resize()
}
const option = ref({
  title: {
    text: '织厂产量',
    /*textVerticalAlign:'center'*/
    top: '0',
    left: '0',
  },
  tooltip: {
    trigger: 'axis',
  },
  grid: {
    left: '3%',
    right: '4%',
    bottom: '0%',
    containLabel: true,
  },
  xAxis: {
    type: 'category',
    data: ['1月', '2月', '3月', '4月', '5月', '6月', '7月', '8月', '9月', '10月', '11月', '12月'],
  },
  yAxis: {
    type: 'value',
    splitNumber: 2,
    // axisLabel: {
    //     formatter: '{value} %'
    // }
  },
  series: [
    {
      name: '月目标',
      type: 'bar',
      // stack: 'Total',
      data: [120, 132, 101, 134, 90, 230, 120],
      label: { show: true, position: 'top', distance: 10 },
    },
    {
      name: '累计总产量(吨)',
      type: 'bar',
      // stack: 'Total',
      data: [220, 182, 191, 234, 290, 330, 310],
      label: { show: true, position: 'top', distance: 10 },
    },
    {
      name: '日产目标值(吨/天)',
      type: 'line',
      data: [150, 232, 201, 154, 190, 330, 410],
      label: { show: true, position: 'top', distance: 10 },
    },
    {
      name: '日均产量(吨/天)',
      type: 'line',
      data: [150, 232, 201, 154, 190, 330, 410],
      label: { show: true, position: 'top', distance: 10 },
    },
  ],
})

//初始化
onMounted(async () => {
  selectJt()
  // state = states()
  // state.setOption(option.value)
})
const myChart: any = ref()
const states = () => {
  return echarts.init(myChart.value)
}
function selectJt() {
  post({
    url: 'qms/report/companyOutputReport',
    data: {
      firmId: query.planOrderCode,
      year: Number(query.beginDate),
    },
  }).then((res: any) => {
    if (res.code == 200) {
      let ob = {}
      let ob1 = {}
      let ob2 = {}
      let ob3 = {}
      res.data.forEach((o: any, index: any) => {
        for (let key in o) {
          if (key == 'goalByDay') {
            ob['project'] = '日产目标值（吨/天）'
            if (index == 0) {
              ob['oneMonth'] = o['goalByDay']
            } else if (index == 1) {
              ob['twoMonth'] = o['goalByDay']
            } else if (index == 2) {
              ob['threeMonth'] = o['goalByDay']
            } else if (index == 3) {
              ob['fourMonth'] = o['goalByDay']
            } else if (index == 4) {
              ob['fiveMonth'] = o['goalByDay']
            } else if (index == 5) {
              ob['sixMonth'] = o['goalByDay']
            } else if (index == 6) {
              ob['sevenMonth'] = o['goalByDay']
            } else if (index == 7) {
              ob['eightMonth'] = o['goalByDay']
            } else if (index == 8) {
              ob['nineMonth'] = o['goalByDay']
            } else if (index == 9) {
              ob['tenMonth'] = o['goalByDay']
            } else if (index == 10) {
              ob['elevenMonth'] = o['goalByDay']
            } else if (index == 11) {
              ob['twelveMonth'] = o['goalByDay']
            }
          }
          if (key == 'outputByDay') {
            ob1['project'] = '日均产量（吨/天）'
            if (index == 0) {
              ob1['oneMonth'] = o['outputByDay']
            } else if (index == 1) {
              ob1['twoMonth'] = o['outputByDay']
            } else if (index == 2) {
              ob1['threeMonth'] = o['outputByDay']
            } else if (index == 3) {
              ob1['fourMonth'] = o['outputByDay']
            } else if (index == 4) {
              ob1['fiveMonth'] = o['outputByDay']
            } else if (index == 5) {
              ob1['sixMonth'] = o['outputByDay']
            } else if (index == 6) {
              ob1['sevenMonth'] = o['outputByDay']
            } else if (index == 7) {
              ob1['eightMonth'] = o['outputByDay']
            } else if (index == 8) {
              ob1['nineMonth'] = o['outputByDay']
            } else if (index == 9) {
              ob1['tenMonth'] = o['outputByDay']
            } else if (index == 10) {
              ob1['elevenMonth'] = o['outputByDay']
            } else if (index == 11) {
              ob1['twelveMonth'] = o['outputByDay']
            }
          }
          if (key == 'goalByMonth') {
            ob2['project'] = '月目标'
            if (index == 0) {
              ob2['oneMonth'] = o['goalByMonth']
            } else if (index == 1) {
              ob2['twoMonth'] = o['goalByMonth']
            } else if (index == 2) {
              ob2['threeMonth'] = o['goalByMonth']
            } else if (index == 3) {
              ob2['fourMonth'] = o['goalByMonth']
            } else if (index == 4) {
              ob2['fiveMonth'] = o['goalByMonth']
            } else if (index == 5) {
              ob2['sixMonth'] = o['goalByMonth']
            } else if (index == 6) {
              ob2['sevenMonth'] = o['goalByMonth']
            } else if (index == 7) {
              ob2['eightMonth'] = o['goalByMonth']
            } else if (index == 8) {
              ob2['nineMonth'] = o['goalByMonth']
            } else if (index == 9) {
              ob2['tenMonth'] = o['goalByMonth']
            } else if (index == 10) {
              ob2['elevenMonth'] = o['goalByMonth']
            } else if (index == 11) {
              ob2['twelveMonth'] = o['goalByMonth']
            }
          }
          if (key == 'outputByTotal') {
            ob3['project'] = '累计总产量（吨）'
            if (index == 0) {
              ob3['oneMonth'] = o['outputByTotal']
            } else if (index == 1) {
              ob3['twoMonth'] = o['outputByTotal']
            } else if (index == 2) {
              ob3['threeMonth'] = o['outputByTotal']
            } else if (index == 3) {
              ob3['fourMonth'] = o['outputByTotal']
            } else if (index == 4) {
              ob3['fiveMonth'] = o['outputByTotal']
            } else if (index == 5) {
              ob3['sixMonth'] = o['outputByTotal']
            } else if (index == 6) {
              ob3['sevenMonth'] = o['outputByTotal']
            } else if (index == 7) {
              ob3['eightMonth'] = o['outputByTotal']
            } else if (index == 8) {
              ob3['nineMonth'] = o['outputByTotal']
            } else if (index == 9) {
              ob3['tenMonth'] = o['outputByTotal']
            } else if (index == 10) {
              ob3['elevenMonth'] = o['outputByTotal']
            } else if (index == 11) {
              ob3['twelveMonth'] = o['outputByTotal']
            }
          }
        }
      })
      let list: any = []
      let list1: any = []
      let list2: any = []
      let list3: any = []
      for (let key in ob) {
        if (key.indexOf('one') != -1) {
          list2[0] = ob[key]
        }
        if (key.indexOf('two') != -1) {
          list2[1] = ob[key]
        }
        if (key.indexOf('three') != -1) {
          list2[2] = ob[key]
        }
        if (key.indexOf('four') != -1) {
          list2[3] = ob[key]
        }
        if (key.indexOf('five') != -1) {
          list2[4] = ob[key]
        }
        if (key.indexOf('six') != -1) {
          list2[5] = ob[key]
        }
        if (key.indexOf('seven') != -1) {
          list2[6] = ob[key]
        }
        if (key.indexOf('eight') != -1) {
          list2[7] = ob[key]
        }
        if (key.indexOf('nine') != -1) {
          list2[8] = ob[key]
        }
        if (key.indexOf('ten') != -1) {
          list2[9] = ob[key]
        }
        if (key.indexOf('eleven') != -1) {
          list2[10] = ob[key]
        }
        if (key.indexOf('twelveMonth') != -1) {
          list2[11] = ob[key]
        }
      }
      for (let key in ob1) {
        if (key.indexOf('one') != -1) {
          list3[0] = ob1[key]
        }
        if (key.indexOf('two') != -1) {
          list3[1] = ob1[key]
        }
        if (key.indexOf('three') != -1) {
          list3[2] = ob1[key]
        }
        if (key.indexOf('four') != -1) {
          list3[3] = ob1[key]
        }
        if (key.indexOf('five') != -1) {
          list3[4] = ob1[key]
        }
        if (key.indexOf('six') != -1) {
          list3[5] = ob1[key]
        }
        if (key.indexOf('seven') != -1) {
          list3[6] = ob1[key]
        }
        if (key.indexOf('eight') != -1) {
          list3[7] = ob1[key]
        }
        if (key.indexOf('nine') != -1) {
          list3[8] = ob1[key]
        }
        if (key.indexOf('ten') != -1) {
          list3[9] = ob1[key]
        }
        if (key.indexOf('eleven') != -1) {
          list3[10] = ob1[key]
        }
        if (key.indexOf('twelveMonth') != -1) {
          list3[11] = ob1[key]
        }
      }
      for (let key in ob2) {
        if (key.indexOf('one') != -1) {
          list[0] = ob2[key]
        }
        if (key.indexOf('two') != -1) {
          list[1] = ob2[key]
        }
        if (key.indexOf('three') != -1) {
          list[2] = ob2[key]
        }
        if (key.indexOf('four') != -1) {
          list[3] = ob2[key]
        }
        if (key.indexOf('five') != -1) {
          list[4] = ob2[key]
        }
        if (key.indexOf('six') != -1) {
          list[5] = ob2[key]
        }
        if (key.indexOf('seven') != -1) {
          list[6] = ob2[key]
        }
        if (key.indexOf('eight') != -1) {
          list[7] = ob2[key]
        }
        if (key.indexOf('nine') != -1) {
          list[8] = ob2[key]
        }
        if (key.indexOf('ten') != -1) {
          list[9] = ob2[key]
        }
        if (key.indexOf('eleven') != -1) {
          list[10] = ob2[key]
        }
        if (key.indexOf('twelveMonth') != -1) {
          list[11] = ob2[key]
        }
      }
      for (let key in ob3) {
        if (key.indexOf('one') != -1) {
          list1[0] = ob3[key]
        }
        if (key.indexOf('two') != -1) {
          list1[1] = ob3[key]
        }
        if (key.indexOf('three') != -1) {
          list1[2] = ob3[key]
        }
        if (key.indexOf('four') != -1) {
          list1[3] = ob3[key]
        }
        if (key.indexOf('five') != -1) {
          list1[4] = ob3[key]
        }
        if (key.indexOf('six') != -1) {
          list1[5] = ob3[key]
        }
        if (key.indexOf('seven') != -1) {
          list1[6] = ob3[key]
        }
        if (key.indexOf('eight') != -1) {
          list1[7] = ob3[key]
        }
        if (key.indexOf('nine') != -1) {
          list1[8] = ob3[key]
        }
        if (key.indexOf('ten') != -1) {
          list1[9] = ob3[key]
        }
        if (key.indexOf('eleven') != -1) {
          list1[10] = ob3[key]
        }
        if (key.indexOf('twelveMonth') != -1) {
          list1[11] = ob3[key]
        }
      }
      option.value.series[0].data = list
      option.value.series[1].data = list1
      option.value.series[2].data = list2
      option.value.series[3].data = list3

      state = states()
      state.setOption(option.value)
    } else {
      Message.error(res.message)
    }
  })
}
</script>
  <script lang="ts">
export default defineComponent({
  name: 'MonthlyOutputOfTheWeavingPlant',
})
</script>
  <style scoped>
.contioner {
  width: 100%;
  height: 100%;
  background: #fff;
  padding: 10px;
}

:deep(.ag-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-header-cell) {
  border-right: 1px solid #dde2eb;
}

:deep(.ag-cell-value) {
  user-select: initial;
  -moz-user-select: text;
  -ms-user-select: text;
  -webkit-user-select: text;
}
</style>
      